﻿using DeepEarth.Map.Core;
using System;
using System.Collections.Generic;
using DeepEarth.Map.Core.Utilities;
using System.Windows;
using DeepEarth.Map.Core.Tiling;

namespace DeepEarth.Map.TileSources
{
    public class QuadKeyTileSource : BaseTileSource
    {
        // 22 - Maximum when dealing with imagesizes of type signed int and the default tile size is 256 (2^8)
        private const int DefaultMaxZoomLevel = 22;
        private const int DefaultTileSize = 256;

        public QuadKeyTilePath PathFormatter {get;set;}

        //Constructor Called by XAML instantiation; Wait for MapMode to be set to initialize services
        public QuadKeyTileSource()
            : base((int)Math.Pow(2, DefaultMaxZoomLevel) * DefaultTileSize,
                   (int)Math.Pow(2, DefaultMaxZoomLevel) * DefaultTileSize,
                   DefaultTileSize,
                   DefaultTileSize,
                    0)
        {
            PathFormatter = new QuadKeyTilePath();
        }

        public QuadKeyTileSource(MapMode specification)
            : base(specification, (int)Math.Pow(2, DefaultMaxZoomLevel) * DefaultTileSize,
                   (int)Math.Pow(2, DefaultMaxZoomLevel) * DefaultTileSize,
                   DefaultTileSize,
                   DefaultTileSize,
                    0)
        {
            PathFormatter = new QuadKeyTilePath();
        }


        protected override string GetTileUri(int zoom, int tilePositionX, int tilePositionY)
        {
            return PathFormatter.GetUri(zoom, tilePositionX, tilePositionY);
        }

	}
}
